{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Generative Adversarial Models"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```{note}\n",
    "Generative adversarial networks are often abbreviated as GANs.\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## What do GANs do?\n",
    "\n",
    "GANs are used to generate things. A face generator may use GANs to generate new faces. A property owner may use GANs to generate the images of their property. GANs are used when we need almost-good-as-real data. Such as a fake photo, fake song etc."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## How do GANs work?\n",
    "\n",
    "Generating things are not easy. Even us humans aren't that good at producing things. Think of the last time you try to create a new song or paint. It's really difficult.\n",
    "\n",
    "GANs do this by using competition. There are two players in this game: A **generator** and a **discriminator**. A generator is used to generate your target image/audio/video etc. A discriminator is used to tell how good the result is: it tries to tell the real images from the fake ones.\n",
    "\n",
    "Initially, both generator and discriminator are bad at doing their jobs. A generator generates things that are very rough. Discriminator has no experiences at all. However, as times go on, both get more experiences. Generators try its best to fool the discriminator, and discriminator try to discriminate the real images from the fake ones. The end result is that generators get so good at creating good images that the images it creates can fool us humans (but maybe not discriminators)!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## GANs in algorithm.\n",
    "\n",
    "Settings:\n",
    "Generator $ G $\n",
    "Discriminator $ D $\n",
    "Real data $ X $\n",
    "\n",
    "Generate some fake data from $ G $. We call this fake data $ \\tilde{X} $.\n",
    "$ D $ is a binary classifier, which outputs $ 1 $ when $ X $ is encountered, and $ 0 $ when $ \\tilde{X} $ is seen.\n",
    "$ D $ tries to get the result of $ D(X) $ close to $ 1 $, and $ D(\\tilde{X}) $ close to $ 0 $.\n",
    "$ G $ tries to generate $ \\tilde{X} $ so that $ D(\\tilde{X}) $ gets close to $ 1 $.\n",
    "Repeat the above procedure many times. Voila, you have a good generator ready to generate fake things!"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
